package chuangyi.com.org.ViewModel;

import android.content.Context;

import com.android.databinding.library.baseAdapters.BR;
import com.solidfire.gson.internal.LinkedTreeMap;

import java.util.ArrayList;

import chuangyi.com.org.DOMIHome.R;
import chuangyi.com.org.DOMIHome.Utils.Utils;
import chuangyi.com.org.DOMIHome.Utils.WebApi;
import chuangyi.com.org.DOMIHome.adapter.XListAdapterInterface;
import chuangyi.com.org.DOMIHome.adapter.XListBindingAdapter;

/**
 * Created by zxh on 16/12/14.
 */
public class MyQuestionModel extends XListModel {

    public MyQuestionModel(Context conetxt) {
        super(conetxt);
        super.getHandler().setTitle("我的问题");
        getAdapter().setVariableId(BR.adviceInfo);
    }

    @Override
    public void load(final int page) {
        new Thread(new Runnable() {
            @Override
            public void run() {
//"consultid":"6","expertid":"","uid":"","question":"",
// "systime":"2016\/12\/03 10:49:48","payflag":"0",
// "username":null,"status":"未回答"
                XListAdapterInterface adapter = getAdapter();
                Context context = getContext();
                ArrayList list = WebApi.myExpertAsk(getContext(), page);
                try {
                    for (Object item : list) {
                        LinkedTreeMap map = (LinkedTreeMap) item;
                        AdviceListItem adviceItem = new AdviceListItem(context, R.layout.i_myadvice);
                        adviceItem.setSystime(Utils.getDateFromFormat(map.get("systime"), "yyyy/MM/dd HH:mm:ss"));
                        adviceItem.setAdviceId(Utils.getIntValue(map.get("consultid")));
                        adviceItem.setExpertId(Utils.getIntValue(map.get("expertid")));
                        adviceItem.setUid(Utils.getIntValue(map.get("uid")));
                        adviceItem.setQuestion((String) map.get("question"));
                        adviceItem.setPayflag(Utils.getBooleanValue((String) map.get("payflag")));
                        adviceItem.setStatus((String) map.get("status"));
                        adviceItem.setName((String) map.get("username"));
                        adviceItem.setExpert(true);
//                    adviceItem.setExpertName((String)map.get(""));
                        adapter.add(adviceItem);
                    }
                } catch (Exception ex) {
                    showToast("解析数据时发生错误");
                }
                if (list.size() > 0) {
                    setCurrentPage(page);
                }
                notifyDataSetChanged(list);
            }
        }).start();
    }
}
